package com.zhao.service.impl;

import com.zhao.dao.UserDao;
import com.zhao.entity.Position;
import com.zhao.entity.User;
import com.zhao.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<User> findAll() {
        return userDao.findAll();
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public User findById(String id) {
        return userDao.findById(id);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void deleteUserById(String id) {
        userDao.deleteUserById(id);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void updateUserById(String id) {
        userDao.updateUserById(id);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void addUser(User user) {
        userDao.addUser(user);
    }

    @Override
    public List<Map<String, Object>> getUserAndPosition(String id) {
        return userDao.getUserAndPosition(id);
    }
}
